<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #box {
            width: 100px;
            height: 100px;
            background-color: red;
            position: absolute; /*一定要记得加定位*/
        }
    </style>
</head>
<body>
<div id="box"></div>
<script>
    var timer = null;
    var y = 0;
    //让盒子移动
    var box = document.getElementById("box");
    timer = setInterval(function () {
        if (y < 300) {
            y++;
            box.style.top = y + "px";//一定要记得加单位
        } else {
            clearInterval(timer);
        }
    }, 15);
</script>
</body>
</html>